// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/widget/layout/FFImageButton.dart';
import 'package:mybase/base/widget/layout/FFNavi.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFListScaffold.dart';

/**List演示 */
class FFListPage extends FFListScaffold {
  String? name;
  FFListPage({Key? key, this.name="演示"}) : super(key: key);

  @override
  FFListPageState createState() => FFListPageState();
}

class FFListPageState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;
  @override
  FFListPage get widget => super.widget as FFListPage;
  @override
  IFFRefresh? get iffRefresh => FFListPageStateRefresh(state: this); ///刷新控制
  /**固定写法end */



  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNaviFast.navi(
      context,
      "ListView页面",
      color: Colors.black,
      actionView: FFTextButton(
        text: "点我",
        alignment: Alignment.center,
        color: Colors.white,
        width: 60,
        heigth: FFNaviHeight,
        onClick: () {
          // FFPageStatus.firstLoading,
          // FFPageStatus.noData,
          // FFPageStatus.netError,
          // FFPageStatus.result
          iffScaffold.ffPageStatus = FFPageStatus.result;
          setState(() {});
        },
      ),
    );
  }

  @override
  Widget ffItem(BuildContext context, int index) {
    return FFImageButton(
      margin: EdgeInsets.only(bottom: 2),
      color: Colors.grey,
      image: null,
      heigth: 66,
    );
  }

  @override
  int ffItemCount() {
    return 20;
  }

}

/**刷新控制 with MFFRefresh */
class FFListPageStateRefresh with MFFRefresh{

  FFListPageState state;
  FFListPageStateRefresh({required this.state});

  @override
  bool? ffCanRefreshHead() {
    return true;
  }

  @override
  bool? ffCanRefreshFoot() {
    return true;
  }

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  //具体请求业务
  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    // 模拟请求调接口
    debugPrint("调用接口... ${state.widget.name}");
    await Future.delayed(Duration(seconds: 2), () {});

    // 模拟到请求的数据
    return R(
      msg: "请求",
      code: "1",
      haveNext: false,
      rStatus: RStatus.result,
    );
  }
}

